﻿/* 
┏━━━━━━━━━━━＼／━━━━━━━━━━━┓      
┃┏━━━━━━━━━━━━━━━━━━━━━━┓┃
     ------------------------------------------    
       Author           : TengSea   
       Created          : Mouth-Day-Year                              
       Last Modified By : TengSea                                 
       Last Modified On : Mouth-Day-Year                                                               
       Description      : 
     __________________________________________
     Copyright (c) TengSea. All rights reserved.
 ┃┗━━━━━━━━━━━━━━━━━━━━━━┛┃                            
 ┗━━━━━━━━━∪━━━━∪━━━━━━━━━┛
 */

using Dapper;
using Hhmocon.Mes.Application.Response;
using Hhmocon.Mes.DataBase.SqlServer;
using Hhmocon.Mes.Repository.Domain;
using Hhmocon.Mes.Util.AutofacManager;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hhmocon.Mes.Repository.Repository.Energy.Energy_Elecdistribution
{
    public class EnergyElecdistributionRepository : IEnergyElecdistributionRepository, IDependency
    {


        public List<elec_distribution_meter> GetGridElecdistribution(DateTime StartTime, DateTime EndTime)
        {
            if (StartTime > EndTime)
            {
                throw new Exception("开始时间不能小于结束时间");
            }
            if (StartTime.Year < 2000 || EndTime.Year < 2000)
            {
                throw new Exception("查询的年份不能小于2000年");
            }
            using (var conn = SqlServerDbHelper.GetConn())
            {
                if (conn.State == ConnectionState.Closed)
                    conn.Open();

                EndTime = new DateTime(EndTime.Year, EndTime.Month, EndTime.Day, 23, 59, 59);
                List<GetGridElecdistributionResponse> resposne = new();
                string sql = $"select * from elec_distribution_meter where consumption_date between '{StartTime}' and '{EndTime}' and delete_mark = 0";
                List<elec_distribution_meter> elec_Distribution_Meters= conn.Query<elec_distribution_meter>(sql).ToList();
                return elec_Distribution_Meters;
            }
        }

        public List<elec_distribution_meter> GetGridElecdistribution()
        {
            using (var conn = SqlServerDbHelper.GetConn())
            {
                if (conn.State == ConnectionState.Closed)
                    conn.Open();

                List<GetGridElecdistributionResponse> resposne = new();
                string sql = $"select * from elec_distribution_meter where delete_mark = 0";
                List<elec_distribution_meter> elec_Distribution_Meters = conn.Query<elec_distribution_meter>(sql).ToList();
                return elec_Distribution_Meters;
            }
        }

    }
}
